package com.oocl.query.util;

import java.io.IOException;
import java.util.List;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.oocl.query.dao.InfomationDao;
import com.oocl.query.pojo.Infomation;

public class JsonObjectConvertor {
	public static String wrapToJson(Object obj){
		ObjectMapper mapper = new ObjectMapper();
		try {
			return mapper.writeValueAsString(obj);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		return null;  
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static Object jsonToObj(String json, Class clazz) {
		ObjectMapper mapper = new ObjectMapper();
		try {
			return mapper.readValue(json, clazz);
			
		} catch (JsonParseException e) {
			e.printStackTrace();
		} catch (JsonMappingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static String wrapToJsonFromList(List<Infomation> list){
		Gson gson = new Gson();
		String jsonStr = gson.toJson(list);
		return jsonStr;
	}
}
